package es.urjc.adrh.injection;

import java.lang.reflect.Field;

public class TestClass {

	@LeaveNull
	String attributeTest; 
	
	public static void main(String[] args) throws SecurityException,
			NoSuchFieldException, IllegalArgumentException, IllegalAccessException{
		
		TestClass test = new TestClass();
		
		//Before process the attribute
		if (test.attributeTest==null)
			System.out.println("Can't read attribute test because of null");
		
		
		//Processes and initializes it
		System.out.println("Processing...");
		
		Field f = test.getClass().getDeclaredField("attributeTest");
		LeaveNull ln =	f.getAnnotation(LeaveNull.class);
		if (ln !=null){
			if (test.attributeTest == null)
				f.set(test, "it is initialized :)");
		}
		System.out.println("Now you can read it because " + test.attributeTest);
	}
}
